package com.deram.ctin.rest.web.controller.web;

import com.deram.ctin.common.bean.Page;
import com.deram.ctin.common.bean.PageResult;
import com.deram.ctin.dependencies.rest.base.BaseController;
import com.deram.ctin.rest.web.result.web.WebEnterDownloadGenerateGexfResult;
import com.deram.ctin.serv.business.api.*;
import com.deram.ctin.serv.business.entity.BusinessShareholder;
import com.deram.ctin.serv.business.filter.BusinessShareholderFilter;
import com.deram.ctin.serv.enter.api.EnterChangeLogApi;
import com.deram.ctin.serv.enter.api.EnterInfoApi;
import com.deram.ctin.serv.enter.api.EnterMainUserApi;
import com.deram.ctin.serv.enter.entity.EnterChangeLog;
import com.deram.ctin.serv.enter.entity.EnterInfo;
import com.deram.ctin.serv.enter.entity.EnterMainUser;
import com.deram.ctin.serv.enter.filter.EnterChangeLogFilter;
import com.deram.ctin.serv.enter.filter.EnterInfoFilter;
import com.deram.ctin.serv.enter.filter.EnterMainUserFilter;
import com.deram.ctin.serv.main.api.EnterRelationApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/28
 */
@Api(tags = {"web - 企业基本信息接口"})
@RestController
@RequestMapping("/web/enter")
public class WebEnterBaseInfoController extends BaseController {

    @Autowired
    private EnterInfoApi enterInfoApi;

    @Autowired
    private EnterMainUserApi enterMainUserApi;

    @Autowired
    private EnterChangeLogApi enterChangeLogApi;

    @Autowired
    private BusinessShareholderApi businessShareholderApi;

    @Autowired
    private EnterRelationApi enterRelationApi;

    @ApiOperation(value = "股东信息分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
    })
    @GetMapping("/searchShareholder/{id}")
    public PageResult<BusinessShareholder> searchShareholder(@PathVariable Long id, Page page){
        BusinessShareholderFilter filter = new BusinessShareholderFilter();
        filter.setEnterId(id);
        return businessShareholderApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "主要人员分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
    })
    @GetMapping("/searchMainUser/{id}")
    public PageResult<EnterMainUser> searchMainUser(@PathVariable Long id, Page page) {
        EnterMainUserFilter filter = new EnterMainUserFilter();
        filter.setEnterId(id);
        return enterMainUserApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "工商变更分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
    })
    @GetMapping("/searchChangeLog/{id}")
    public PageResult<EnterChangeLog> searchEnterChangeLog(@PathVariable Long id, Page page){
        EnterChangeLogFilter filter = new EnterChangeLogFilter();
        filter.setEnterId(id);
        return enterChangeLogApi.search(filter,page.getPageNo(),page.getPageSize());
    }

    @ApiOperation(value = "分支机构分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
    })
    @GetMapping("/searchEnterInfo/{id}")
    public PageResult<EnterInfo> searchEnterInfo(@PathVariable Long id, Page page){
        EnterInfoFilter enterInfoFilter = new EnterInfoFilter();
        enterInfoFilter.setFatherId(id);
        return enterInfoApi.search(enterInfoFilter,page.getPageNo(),page.getPageSize());
    }

    @ApiOperation(value = "企业关系 - 生成GEXF")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path")
    })
    @PostMapping("/enterRelation/generateGexf/{id}")
    public WebEnterDownloadGenerateGexfResult generateGexf(@PathVariable Long id){
        WebEnterDownloadGenerateGexfResult result = new WebEnterDownloadGenerateGexfResult();
        EnterInfo enterInfo = enterRelationApi.execGenerateGexf(id);
        result.setUrl(enterInfo.getGexfUrl());
        return result;
    }
}
